package com.drondea.sms.common.util;

import java.net.InetSocketAddress;

import com.drondea.sms.type.GlobalConstants;

import io.netty.channel.Channel;
import io.netty.util.Attribute;

/**
 * 获取IP
 * @author zhongbaoluo
 *
 */
public class IpUtil {

	public static String getIp(Channel channel) {
		Attribute<String> attribute = channel.attr(GlobalConstants.CLIENT_IP_KEY);
		if(attribute!=null && attribute.get()!=null) {
			return attribute.get();
		}
		
		InetSocketAddress remoteAddress = (InetSocketAddress) channel.remoteAddress();
        return remoteAddress.getAddress().getHostAddress();
	}
}
